#!/bin/sh
exstat=1
trap 'rm -f Makefile dummy; exit $exstat' 0 1 2 3 15
#
# Yet another Apache Configure helper script.
# This one exists simply to test for the existance of
# a library. It does so by using ../Makefile.config to get
# things like the C-compiler, etc, and then trying to
# compile a dummy program and linking it with that
# library. If the linking succeeds, then we assume that
# library exists and we print out "yes" otherwise we
# print out "no"
#
# This must be run as './helpers/TestLib <libname>' from
# the ./src directory (same directory that Configure is
# located) if you want to test it out. Configure must
# also call it as './helpers/TestLib <libname>'
#

#
# Make sure we have an argument
#
if [ "x$1" = "x" ]; then
  exit
fi

#
# Get makefile settings and build a basic Makefile
#
cd ./helpers
rm -f dummy
cat ../Makefile.config > Makefile
cat <<EOF >> Makefile
CFLAGS=\$(OPTIM) \$(CFLAGS1) \$(EXTRA_CFLAGS)
LIBS=\$(EXTRA_LIBS) \$(LIBS1)
INCLUDES=\$(INCLUDES1) \$(EXTRA_INCLUDES)
LDFLAGS=\$(LDFLAGS1) \$(EXTRA_LDFLAGS)

dummy:
	\$(CC) \$(CFLAGS) \$(INCLUDES) \$(LDFLAGS) dummy.c -o dummy -l$1

EOF

# Now run that Makefile
make dummy > /dev/null 2<&1

# And see if dummy exists, if so, then we assume the 
# library we are testing for exists
if [ -f dummy ]; then
    exstat=0
fi
